package com.test.io;

import java.io.File;

public class Find {
	
	public File find(String root, String target) {
		System.out.println("traversing " + root + "...");
		
		File dir = new File(root);
		File[] children = dir.listFiles();
		for(int i = 0; i < children.length; i++) {
			if(target.equals(children[i].getName())) {
				return children[i];
			}
			if(children[i].isDirectory()) {
				File found = find(children[i].getAbsolutePath(), target);
				if(found != null) return found;
			}
		}
		return null;
	}

	public static void main(String[] args) {
		String root = "D:/temp";
		String target = "[Vega]Rambo-mobile.mp4";
		
		Find find = new Find();
		File found = find.find(root, target);
		if(found != null)
			System.out.println("Found: " + found.getAbsolutePath());
		else
			System.out.println("Not found");
	}
}
